import java.util.ArrayList;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: qian
 * Date: 2023-01-03
 * Time: 14:41
 */
//懒汉模式
class lazySingleton{
    private volatile static lazySingleton instance=null;
    //在使用的时候new对象
    public static lazySingleton getInstance(){
        //判断是否要加锁
        if(instance ==null) {
            synchronized (lazySingleton.class) {
                //判断是否要创建实例
                if (instance == null) {
                    instance = new lazySingleton();
                }
            }
        }
        return instance;
    }
    private lazySingleton(){

    }
}

public class Demo2 {
    public static void main(String[] args) {
        lazySingleton instance=lazySingleton.getInstance();
    }
}
